package fy.EAM.operator;

import java.util.ArrayList;
import java.util.List;

import com.seeyon.v3x.services.flow.bean.FlowExport;
import com.seeyon.v3x.services.form.bean.ValueExport;

import fy.EAM.bean.maintenancebean;
import fy.EAM.dao.maintenancedao;
import fy.form.listen.operate.AForm_Save_Operator;
import fy.form.listen.operate.IFormOperator;

public class maintenanceoperator extends AForm_Save_Operator implements IFormOperator {
	private maintenancebean bean= new maintenancebean();
	private List<String> sparePartsCodeList = new ArrayList<String>();
	private List<String> sparePartsQuantityList = new ArrayList<String>();
	private List<String> sparePartsNameList = new ArrayList<String>();
	@Override
	public String getFormName() {
		// TODO Auto-generated method stub
		return "EAM维修数据写入";
	}

	@Override
	protected void parseOtherField_FirstStep(FlowExport flowExport) {
		// TODO Auto-generated method stub
		
	}

	@Override
	protected void parseValueExport(ValueExport ve) {
		// TODO Auto-generated method stub
		String fieldName = ve.getDisplayName();
		if ("申请人".equals(fieldName)) {
			bean.setProposer(ve.getValue());
		} else if ("申请人工号".equals(fieldName)) {
			bean.setUserId(ve.getValue());
		} else if ("申请部门".equals(fieldName)) {
			bean.setApplyDepartment(ve.getValue());
		} else if ("设备名称".equals(fieldName)) {
			bean.setAssetName(ve.getValue());
		} else if ("资产编号".equals(fieldName)) {
			bean.setAssetNumber(ve.getValue());
		} else if ("联系电话".equals(fieldName)) {
			bean.setTelphone(ve.getValue());
		} else if ("故障现象".equals(fieldName)) {
			bean.setFaultCause(ve.getValue());
		} else if ("型号".equals(fieldName)) {
			bean.setAssetModel(ve.getValue());
		} else if ("序列号".equals(fieldName)) {
			bean.setSerialNumber(ve.getValue());
		} else if ("是否过保".equals(fieldName)) {
			bean.setStatus(ve.getValue());
		} else if ("配置".equals(fieldName)) {
			bean.setAllocation(ve.getValue());
		} else if ("信息部意见".equals(fieldName)) {
			bean.setSuggestion(ve.getValue());
		} else if ("维修结论".equals(fieldName)) {
			bean.setRemark(ve.getValue());
		} else if ("公司名称".equals(fieldName)) {
			bean.setCmpCode(ve.getValue());
		} else if ("备件编码".equals(fieldName)) {
			this.sparePartsCodeList.add(ve.getValue());
		} else if ("备件数量".equals(fieldName)) {
			this.sparePartsQuantityList.add(ve.getValue());
		} else if ("备件名称".equals(fieldName)) {
			this.sparePartsNameList.add(ve.getValue());
		} 
	}

	@Override
	protected boolean save() {
		// TODO Auto-generated method stub
		
		try {
			bean.setSparePartsCode(sparePartsCodeList);
			bean.setSparePartsQuantity(sparePartsQuantityList);
			bean.setSparePartsName(sparePartsNameList);
			maintenancedao dao=new maintenancedao();
			dao.setMaintenancebean(bean);
			return dao.getMaintenance();
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}finally {
			//bean.clear();
			bean = null;
		}
		return success;
	}

}
